<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\6\29 0029
 * Time: 11:28
 */

namespace app\lib\Order\OrderPaymentNotice;


use app\model\OrderPaymentNoticeModel;

class OrderNotice
{
    protected $orderId;
    protected $moneyId;
    protected $table;
    public function __construct($orderId,$moneyId = null)
    {
        $this->orderId = $orderId;
        if(!empty($this->moneyId) && is_numeric($this->moneyId)){
            $this->moneyId =$moneyId;
        }
    }

    protected function getTable(){
        if(empty($this->table)){
            $this->table=new OrderPaymentNoticeModel();
        }
        return $this->table;
    }

    /**
     * 判断是否存在：指定工单通知里是否存在未审核的支付
     * @return bool
     */
    public function isNoReviewPay(){
        $id = $this->getNoReviewPayId();
        return empty($id)?false:true;
    }

    /**
     * 获取指定工单通知里是否存在未审核的支付
     * @return mixed
     */
    public function getNoReviewPayId(){
        $model = $this->getTable();
        $map = [
            $model->_status = 0,$model->_type='pay',$model->_orderId=>$this->orderId,$model->_moneyId=>$this->moneyId
        ];
        $id =  $model->where($map)->value('id');
        return $id;
    }

    /**
     * 获取指定工单通知里是否存在未审核的签收
     * @return mixed
     */
    public function getNoReviewSignId(){
        $model = $this->getTable();
        $map = [
            $model->_status = 0,$model->_type='sign',$model->_orderId=>$this->orderId
        ];
        $id =  $model->where($map)->value('id');
        return $id;
    }

    /**
     * 判断是否存在：指定工单通知里是否存在未审核的签收
     * @return bool
     */
    public function isNoReviewSign(){
        $id = $this->getNoReviewSignId();
        return empty($id)?false:true;
    }

    /**
     * 获取最大签收通知的内容
     * @return mixed
     */
    public function getMaxIdSignNoticeName(){
        $model = $this->getTable();
        $map = [
            $model->_type='sign',$model->_orderId=>$this->orderId
        ];
        $value =  $model->where($map)->order($model->_id.' desc')->value($model->_content);
        return $value;
    }

}